import 'package:arith/arith.dart';
import 'package:arith/src/equations.dart';
import 'package:arith/src/parser.dart';

const _expression = r'-1 + (x + (-2.9 - (~-3 * -4 / -5 + ~-~-~6 - sum(-~-7, 8.9))) + (sqrt(9) - 10) * -11 + y) + 13.8';

num _sum(List<num> values) => values.fold(0, (value, element) => value + element);

void main() {
  print(
    MathParser(_expression)
      ..callable('sum', _sum)
      ..callable('hash', Object.hashAll)
      ..variable('x', () => 10)
      ..variable('y', () => 89.9),
  );
  print(
    Parser('$_expression - 197.10000000000002', {
      const Callable('sum', _sum),
      const Callable('hash', Object.hashAll),
    }).parse().solve(
      symbol: 'x',
      variables: {'y': () => 89.0},
    ),
  );
}
